﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using BOM.entity;
using BOM.dao;

namespace BOM
{
    public partial class UpdateCostForm : Form
    {
        Bom bom;
        public UpdateCostForm(Hashtable ctx)
        {
            InitializeComponent();
            if (ctx["bom"] != null)
            {
                bom = (Bom)ctx["bom"];
                txtNaterialCost.Text = bom.getNaterialCost().ToString();
                txtLabourCost.Text = bom.getLabourCost().ToString();
                txtTotalCost.Text = bom.getTotalCost().ToString();
           
            }
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {          
            DialogResult result = MessageBox.Show(this, "是否确认要提交更新成本值？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            if (result == DialogResult.OK)
            {
                updateCost(bom);
                MessageBox.Show("更新成本操作成功！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtNaterialCost_TextChanged(object sender, EventArgs e)
        {
          //  float naterialCost = float.Parse(txtNaterialCost.Text);
         //   float labourCost = float.Parse(txtLabourCost.Text);
         //   txtTotalCost.Text = (naterialCost + labourCost).ToString();
        }

        private void txtLabourCost_TextChanged(object sender, EventArgs e)
        {
          //  float naterialCost = float.Parse(txtNaterialCost.Text);
          //  float labourCost = float.Parse(txtLabourCost.Text);
          //  txtTotalCost.Text = (naterialCost + labourCost).ToString();
        }

        //更新成本
        public void updateCost(Bom bom)
        {
            BomDaoImp.updateCost(bom);
            if (bom.getParentId() == null || bom.getParentId() == 0)
                return;
            else
            {
                Bom parentBom = BomDaoImp.getBomById(bom.getParentId());
                updateCost(parentBom);
            }
        }
    }
}
